<template>
  <div class="notice">
    <div class="notice-head">
      <div>
        <!-- <el-button type="primary" round class="add-btn" @click="insertNotice"> <i class="iconfont icon-tianjia"></i>
          发布新通知</el-button> -->
      </div>
      <div>
        <!-- <el-select v-model="quesHeadData.difficultLevel" class="select" placeholder="请选择难度" size="small">
          <el-option v-for="item in difficulties" :label="item.label" :value="item.value" />
        </el-select> -->

        <el-input v-model="search" placeholder="请输入知识点名称" class="input">
          <template #append>
            <el-button class="iconfont icon-sousuo3" @click="searchByTitel"></el-button>
          </template>
        </el-input>
      </div>
    </div>
    <div class="notice-body">
      <div class="top">
        <el-select v-model="noticeData.noticeType" class="select" placeholder="全部通知" style="width: 110px">
          <el-option v-for="item in type" :label="item.label" :value="item.value"></el-option>
        </el-select>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router';
import { insertNoticeAPI, getCourseListAPI, getCourseByIdAPI } from '@/api/api'

const router = useRouter()
const noticeData = ref({
  noticeType: '全部通知'
})
const type = reactive([
  {
    label: "全部通知",
    value: '',
  },
  {
    label: "普通通知",
    value: 0,
  },
  {
    label: "考试通知",
    value: 1,
  },
])
const search = ref('')
const addDialog = ref(false)
const knowledgeHeadData = ref({
  //所属课程
  belongCourseId: '',
  //获取到的所有课程
  courses: [],
  //课程列表
  courseList: [],
})
//添加、更新操作数据
const knowledgeData = ref({
  //所属课程
  belongCourseId: '',
  //知识点名
  knowledgeName: '',
  //知识点描述
  knowledgeDescription: '',
  //使用次数
  konwledgeUsed: '0',
})
onMounted(() => {
  //获取课程信息
  getCourseList()
})

//分页查询课程
const getCourseList = async () => {
  await getCourseListAPI().then(res => {
    if (res.data.code == 200) {
      knowledgeHeadData.value.courseList = res.data.data.list
      getCourseName(knowledgeHeadData.value.courseList)
      if (sessionStorage.getItem('knowledgeCourseId')) {
        getCourseById(sessionStorage.getItem('knowledgeCourseId'))
        getBankListCourse(sessionStorage.getItem('knowledgeCourseId'))
      }
    }
  })
}
//获取课程名
const getCourseName = (courseList) => {
  for (let item of courseList) {
    knowledgeHeadData.value.courses.push({
      label: item.courseName,
      value: item.id
    })
  }
}
//根据课程id查询课程名（单查）
const getCourseById = async (id) => {
  await getCourseByIdAPI(id).then(res => {
    knowledgeHeadData.value.belongCourseId = res.data.data.courseName
  })
}
//根据知识点名查询
const searchByTitel = () => {
  getBankListCourse(sessionStorage.getItem('knowledgeCourseId'))
}

//新增通知按钮
const insertNotice = () => {
  // addDialog.value = true
  router.push({
    name: 'publicNotice'
  })
}
</script>

<style lang="less" scoped>
.notice {
  width: 80vw;
  height: 91vh;
  margin: 0 auto;
  background-color: #fff;

  .notice-head {
    margin: 0px auto;
    padding-top: 20px;
    width: 90%;
    min-height: 65px;
    // background-color: #ffffff;
    border-radius: 20px;
    display: flex;
    justify-content: space-between;

    .add-btn {
      padding: 20px;
      margin-left: 20px;

      .icon-tianjia {
        margin-top: -2px;
        margin-right: 3px;
      }
    }

    .input {
      width: 240px;
      height: 40px;
      margin: 0 20px;
    }

    ::v-deep .el-input__wrapper {
      border-radius: 23px 0 0 23px;
      padding-left: 18px;
    }

    ::v-deep .el-input-group__append {
      border-radius: 0 23px 23px 0;
    }



  }

  .notice-body {
    width: 76vw;
    margin: auto;
    .top {
      height: 40px;
      background-color: #f5f6f7;
      display: flex;

      ::v-deep .el-select__wrapper {
        border: none;
        box-shadow: none;
        font-size: 16px;
        background-color: #f5f6f7;
        margin: 4px 0;
      }
    }

  }
}
</style>